package com.campus.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.campus.common.JWTUtil;
import com.campus.config.TokenProvider;
import org.apache.el.parser.Token;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * Mybatis Plus Model 插入操作和更新操作默认值
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Autowired
    private TokenProvider tokenProvider;

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createdTime", new Date(), metaObject);
        this.setFieldValByName("updatedTime", new Date(), metaObject);
//        this.setFieldValByName("status", 0l, metaObject);
        String username = "system";
        this.setFieldValByName("creator", username,metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updatedTime", new Date(), metaObject);
    }
}